// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    private _count = 0;
    start() {
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.touchMove, this);
    }
    public onCollisionEnter(collider1, collider2) {
        this._count++;
        this.node.color = cc.Color.GREEN;
        
    }
    public onCollisionExit(collider1, collider2) {
        this._count--;
        if (this._count <= 0) {
            this.node.color = cc.Color.WHITE;
        }

        // cc.log("exit",this.node.name);
    }

    private touchMove(event: cc.Touch) {
        let delta = event.getDelta();
        delta.x += this.node.x;
        delta.y += this.node.y;
        this.node.setPosition(delta);
    }
}
